
/*
DHT11温湿度传感器接线
DHT11电源 3.3V
数据接引脚D4
*/
#include <Arduino.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"
 
#define DHTTYPE DHT11   // DHT 11
#define DHTPIN 4 
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  Serial.begin(115200);
  dht.begin();
}
 
void loop() {
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.println(h);
  Serial.println(t);
  Serial.println(f);
  delay(30000);
}
 